package com.candy.utils;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class LogAspect {
    @Pointcut("execution(* com.candy.service.*.*(..))")
    public void mypointcut(){

    }
    @Before("mypointcut()")
    public void before(JoinPoint jp){
        String name=jp.getSignature().getName();
        System.out.println(name+"方法开始执行...");
    }
    @After("mypointcut()")
    public void after(JoinPoint jp){
        String name=jp.getSignature().getName();
        System.out.println(name+"方法开始结束...");
    }
    @AfterReturning(value = "mypointcut()",returning="result")
    public void afterReturning(JoinPoint jp,Object result){
        String name=jp.getSignature().getName();
        System.out.println(name+"方法返回值为："+result);
    }
    @AfterThrowing(value = "mypointcut()",throwing = "e")
    public void afterThrowing(JoinPoint jp,Exception e){
        String name=jp.getSignature().getName();
        System.out.println(name+"方法抛出异常"+e.getMessage());
    }
    @Around("mypointcut()")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        return pjp.proceed();
    }


}